package com.resume.controller;

import com.resume.bean.DataTableResponse;
import com.resume.bean.Result;
import com.resume.bean.ResultUtil;
import com.resume.constant.GlobalConst;
import com.resume.domain.${className};
import com.resume.enums.ResultEnum;
import com.resume.ex.ResumeException;
import com.resume.service.${className}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
* @Author: 梁云亮
* @Date: 2021/7/16 16:17
* @Describe:
*/
@Api(value = "${comment}控制器：${className}Controller",tags = "${className}Controller：${comment}控制器")
@Controller
@RequestMapping("/${objName}")
public class ${className}Controller {

    @Resource
    private ${className}Service ${objName}Service;

    @ApiOperation(value = "打开${comment}列表页面", notes = "打开${comment}列表页面")
    @GetMapping("/open${className}")
    public String open${className}(){
        return "/base/${objName}";
    }

    @ApiOperation(value = "显示${comment}列表", notes = "显示${comment}列表")
    @ResponseBody
    @GetMapping("/v1/list")
    public Result <DataTableResponse<${className}>> list() {
        List<${className}> ${objName}List = ${objName}Service.listAllUsable${className}();

        DataTableResponse<${className}> dataTableResponse = new DataTableResponse<>();
        dataTableResponse.setSEcho(3);
        dataTableResponse.setITotalRecords(80L);
        dataTableResponse.setITotalDisplayRecords(70L);
        dataTableResponse.setAaData(${objName}List);
        return ResultUtil.success(200, "数据查询成功", dataTableResponse);
    }

    @ApiOperation(value = "删除${comment}", notes = "根据编号删除${comment}")
    @ResponseBody
    @GetMapping("/v1/remove")
    public Result remove(Integer id) {
        try {
            ${objName}Service.modify${className}Status(id, GlobalConst.Common.STATUS_DISABLE);
            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ResumeException(ResultEnum.SQL_ERROR);
        }
    }

    @ApiOperation(value = "修改${comment}", notes = "根据编号修改${comment}")
    @ResponseBody
    @GetMapping("/v1/modify")
    public Result modify(${className} ${objName}) {
        try {
            ${objName}Service.modify(${objName});
            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ResumeException(ResultEnum.SQL_ERROR);
        }
    }

    @ApiOperation(value = "增加${comment}", notes = "增加${comment}")
    @ResponseBody
    @GetMapping("/v1/create")
    public Result create(${className} ${objName}) {
        try {
            ${objName}Service.save(${objName});
            return ResultUtil.success(ResultEnum.SUCCESS);
        } catch (Exception e) {
            throw new ResumeException(ResultEnum.SQL_ERROR);
        }
    }

}
